package com.cc.controller;


import com.cc.entity.Products;
import com.cc.service.ProductsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/product")
@CrossOrigin    //允许跨域访问
public class ProductsController {
    @Autowired
    ProductsService productsService;

    //获取商品列表
    @PostMapping("/list")
    public List<Products> list(@RequestBody Products products) {
        return productsService.list(products);
    }

    // 添加书籍表单
    @PostMapping("/save")
    public int showAddForm(Products products) {
        return productsService.add(products);
    }
    //更新书籍表单
    @PostMapping("/update")
    public int showEditForm(@RequestBody Products products) {
        return productsService.update(products);
    }
    // 显示编辑书籍表单
    @GetMapping("/edit")
    public Products showEditForm(Integer productId) {
        return productsService.findById(productId);
    }
    // 删除商品
    @GetMapping("/delete")
    public int delete(Integer productId) {
        return productsService.delete(productId);
    }

}